package servletmvc.imooc.service.impl;

import java.util.List;

import servletmvc.imooc.dao.UserDao;
import servletmvc.imooc.dao.impl.UserDaoImpl;
import servletmvc.imooc.entity.User;
import servletmvc.imooc.service.UserService;

public class UserServiceImpl implements UserService{
	//注入dao层的方法
	UserDao userDao = new UserDaoImpl();

	@Override
	public List<User> getUserList() {
		//获取用户列表
		return userDao.queryUserList();
	}

	@Override
	public int addUser(User user) {
		//添加
		return userDao.addUser(user);
	}

	@Override
	public int deleteUserById(Integer id) {
		// del
		return userDao.deleteUserById(id);
	}

	@Override
	public int updateUserById(User user) {
		// up
		return userDao.updateUserById(user);
	}

	@Override
	public User getById(Integer id) {
		// 查询
		return userDao.queryById(id);
	}

	@Override
	public int batchInsertUser(List<User> userList) {
		//批量插入
		//判断集合是否为空
		if(userList != null && userList.size() > 0) {
			return userDao.batchInsertUser(userList);
		}else {
			return 0;
		}
	}

}
